// 'use strict'

var insert = require('./InsertSql/insert');
insert();
var table = require('./module/table');
var Crawler = require('crawler');

var c = new Crawler({
    rateLimit:10,
    maxConnections: 1,
    // This will be called for each crawled page
    callback: function (error, res, done) {
        if (error) {
            console.log(error);
        } else {
            var $ = res.$;

            var list = $('.dw_table .el').toArray();
            list.forEach(element => {
                var txt0 = $(element).find(' .t1 span ').text().trim();
                var txt1 = $(element).find(' .t2 a ').attr('title');
                var txt2 = $(element).find(' .t3 ').text().trim();
                var txt3 = $(element).find(' .t4 ').text().trim();
                var txt4 = $(element).find(' .t5 ').text().trim();
                table.create({ title: txt0, company: txt1, region: txt2,salary:txt3,time:txt4});
                // console.log(txt1);
            });
        }
        done();
1   }
});
for (let index = 1; index <=15 ; index++) {
    c.queue('https://search.51job.com/list/010000%252C180200%252C020000%252C030200%252C040000,000000,7501,00,9,99,%2520,1,'+index+'.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare=');
}



